package com.ssy.lingxi.order.serviceimpl.web;

import cn.hutool.json.JSONUtil;
import com.querydsl.core.types.Projections;
import com.querydsl.jpa.impl.JPAQuery;
import com.querydsl.jpa.impl.JPAQueryFactory;
import com.ssy.lingxi.common.exception.BusinessException;
import com.ssy.lingxi.common.model.dto.MemberAndRoleIdDTO;
import com.ssy.lingxi.common.model.dto.UserLoginCacheDTO;
import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.ResponseCode;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.common.utils.DateTimeUtil;
import com.ssy.lingxi.order.entity.*;
import com.ssy.lingxi.order.model.bo.LogisticsAddressBO;
import com.ssy.lingxi.order.model.constant.*;
import com.ssy.lingxi.order.model.vo.basic.request.*;
import com.ssy.lingxi.order.model.vo.basic.response.ReceiveOrderDetailVO;
import com.ssy.lingxi.order.model.vo.basic.response.ReceiveOrderProductQueryVO;
import com.ssy.lingxi.order.model.vo.basic.response.ReceiveOrderQueryVO;
import com.ssy.lingxi.order.model.vo.common.request.LogisticsAddressVO;
import com.ssy.lingxi.order.repository.ReceiveOrderProductRepository;
import com.ssy.lingxi.order.repository.ReceiveOrderRepository;
import com.ssy.lingxi.order.service.base.IBaseCacheService;
import com.ssy.lingxi.order.service.base.IBaseDeliveryHistoryService;
import com.ssy.lingxi.order.service.base.IBaseOrderDeliveryService;
import com.ssy.lingxi.order.service.web.IDeliveryOrderService;
import com.ssy.lingxi.order.service.web.IDeliveryPlanService;
import com.ssy.lingxi.order.service.web.IReceiveOrderService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.http.HttpHeaders;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

/**
 * 收货计划相关接口实现类
 * @author czh
 * @version 2.0.0
 * @date 2021-07-20
 */
@Slf4j
@Service
public class ReceiveOrderServiceImpl implements IReceiveOrderService {

    @Resource
    private IBaseCacheService baseCacheService;

    @Resource
    private JPAQueryFactory jpaQueryFactory;

    @Resource
    private ReceiveOrderRepository receiveOrderRepository;

    @Resource
    private ReceiveOrderProductRepository receiveOrderProductRepository;

    @Resource
    private IBaseDeliveryHistoryService historyService;

    @Resource
    private StringRedisTemplate stringRedisTemplate;

    @Resource
    private IDeliveryOrderService deliveryOrderService;

    @Resource
    private IBaseOrderDeliveryService baseOrderDeliveryService;

    @Resource
    private IDeliveryPlanService deliveryPlanService;

    private PageData<ReceiveOrderQueryVO> pageBase(MemberAndRoleIdDTO vendor, MemberAndRoleIdDTO buyer, ReceiveOrderPageVO pageVO) {

        QReceiveOrderDO receiveOrderDO = QReceiveOrderDO.receiveOrderDO;
        JPAQuery<ReceiveOrderQueryVO> query = jpaQueryFactory
                .select(Projections.constructor(ReceiveOrderQueryVO.class, receiveOrderDO.id,receiveOrderDO.receiveNo,receiveOrderDO.deliveryNo,receiveOrderDO.digest,receiveOrderDO.deliveryTime,receiveOrderDO.receiveTime,receiveOrderDO.vendorMemberName,receiveOrderDO.buyerMemberName,receiveOrderDO.createTime,receiveOrderDO.outerStatus))
                .from(receiveOrderDO);
        //供应商信息
        if(vendor!=null) {
            query.where(receiveOrderDO.vendorMemberId.eq(vendor.getMemberId()).and(receiveOrderDO.vendorRoleId.eq(vendor.getRoleId())));
            //采购会员名称
            if(!StringUtils.isEmpty(pageVO.getVendorMemberName())) {
                query.where(receiveOrderDO.buyerMemberName.like("%" + pageVO.getVendorMemberName().trim() + "%"));
            }
        }
        //采购商
        if(buyer!=null) {
            query.where(receiveOrderDO.buyerMemberId.eq(buyer.getMemberId()).and(receiveOrderDO.buyerRoleId.eq(buyer.getRoleId())));
            //供应会员名称
            if(!StringUtils.isEmpty(pageVO.getVendorMemberName())) {
                query.where(receiveOrderDO.vendorMemberName.like("%" + pageVO.getVendorMemberName().trim() + "%"));
            }
        }
        //通知单号
        if(!StringUtils.isEmpty(pageVO.getReceiveNo())) {
            query.where(receiveOrderDO.receiveNo.like("%" + pageVO.getReceiveNo().trim() + "%"));
        }

        //摘要
        if(!StringUtils.isEmpty(pageVO.getDigest())) {
            query.where(receiveOrderDO.digest.like("%" + pageVO.getDigest().trim() + "%"));
        }

        //起始时间
        if(!StringUtils.isEmpty(pageVO.getStartDate())) {
            query.where(receiveOrderDO.receiveTime.goe(LocalDateTime.parse(pageVO.getStartDate().concat(" 00:00:00"), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))));
        }

        //结束时间
        if(!StringUtils.isEmpty(pageVO.getEndDate())) {
            query.where(receiveOrderDO.receiveTime.loe(LocalDateTime.parse(pageVO.getEndDate().concat(" 23:59:59"), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))));
        }
        //倒序排序、分页、总数
        query.orderBy(receiveOrderDO.receiveTime.desc(),receiveOrderDO.createTime.desc());
        query.limit(pageVO.getPageSize()).offset(pageVO.getCurrentOffset());
        long totalCount = query.fetchCount();
        return new PageData<>(totalCount, query.fetch());
    }

    @Override
    public Wrapper<PageData<ReceiveOrderQueryVO>> page(HttpHeaders headers, ReceiveOrderPageVO pageVO) {
        UserLoginCacheDTO loginUser = baseCacheService.needLoginFromBusinessPlatform(headers);
        return Wrapper.success(pageBase(null,new MemberAndRoleIdDTO(loginUser.getMemberId(),loginUser.getMemberRoleId()),pageVO));
    }

    private boolean isMemberData(UserLoginCacheDTO loginUser, ReceiveOrderDO deliveryOrderDO){
        if(loginUser==null||deliveryOrderDO==null){return false;}
        return (deliveryOrderDO.getVendorMemberId().equals(loginUser.getMemberId())&&deliveryOrderDO.getVendorRoleId().equals(loginUser.getMemberRoleId()))
        ||(deliveryOrderDO.getBuyerMemberId().equals(loginUser.getMemberId())&&deliveryOrderDO.getBuyerRoleId().equals(loginUser.getMemberRoleId()));
    }

    private boolean isCreator(UserLoginCacheDTO loginUser, ReceiveOrderDO deliveryOrderDO){
        if(loginUser==null||deliveryOrderDO==null){return false;}
        return (deliveryOrderDO.getBuyerMemberId().equals(loginUser.getMemberId())&&deliveryOrderDO.getBuyerRoleId().equals(loginUser.getMemberRoleId()));
    }

    @Override
    public Wrapper<PageData<ReceiveOrderProductQueryVO>> pageProducts(HttpHeaders headers, ReceiveOrderProductPageVO pageVO) {
        UserLoginCacheDTO loginUser = baseCacheService.needLoginFromBusinessPlatform(headers);
        //查询送货单
        ReceiveOrderDO deliveryOrderDO = receiveOrderRepository.findById(pageVO.getId()).orElse(null);
        if(deliveryOrderDO==null||!isMemberData(loginUser,deliveryOrderDO)){
            return Wrapper.success(new PageData<>(0L, Collections.emptyList()));
        }
        QReceiveOrderProductDO qOrderProduct = QReceiveOrderProductDO.receiveOrderProductDO;
        JPAQuery<ReceiveOrderProductQueryVO> query = jpaQueryFactory
                .select(Projections.constructor(ReceiveOrderProductQueryVO.class,qOrderProduct.id,qOrderProduct.skuId,qOrderProduct.productName,qOrderProduct.orderNo,qOrderProduct.createTime,qOrderProduct.type,qOrderProduct.category,qOrderProduct.brand,qOrderProduct.unit,qOrderProduct.purchaseCount,qOrderProduct.deliveryCount,qOrderProduct.receiveCount))
                .from(qOrderProduct)
                .where(qOrderProduct.receiveOrder.id.eq(pageVO.getId()));
        long totalCount = query.fetchCount();
        List<ReceiveOrderProductQueryVO> fetch = query.limit(pageVO.getPageSize()).offset(pageVO.getCurrentOffset()).fetch();
        return Wrapper.success(new PageData<>(totalCount, fetch));
    }

    private LogisticsAddressBO buildLogisticsAddressBO(LogisticsAddressVO param){
        if(param==null){return null;}
        LogisticsAddressBO addressBO=new LogisticsAddressBO();
        addressBO.setConsignee(param.getConsignee());
        addressBO.setProvinceName(param.getProvinceName());
        addressBO.setCityName(param.getCityName());
        addressBO.setDistrictName(param.getDistrictName());
        addressBO.setStreetName(param.getStreetName());
        addressBO.setAddress(param.getAddress());
        addressBO.setPhone(param.getPhone());
        addressBO.setCarNumbers(param.getCarNumbers());
        return addressBO;
    }

    private LogisticsAddressVO convertLogisticsAddressVO(LogisticsAddressBO param){
        if(param==null){return null;}
        LogisticsAddressVO addressVO=new LogisticsAddressVO();
        addressVO.setConsignee(param.getConsignee());
        addressVO.setProvinceName(param.getProvinceName());
        addressVO.setCityName(param.getCityName());
        addressVO.setDistrictName(param.getDistrictName());
        addressVO.setStreetName(param.getStreetName());
        addressVO.setAddress(param.getAddress());
        addressVO.setPhone(param.getPhone());
        addressVO.setCarNumbers(param.getCarNumbers());
        return addressVO;
    }

    private String createOrderSn(String orderSn) {
        String currentTimeOrderSn = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"));
        String orderSnKey = orderSn + currentTimeOrderSn;
        //订单号后面6位随机数
        String orderSnSuffix = stringRedisTemplate.opsForValue().get(orderSnKey);
        if (StringUtils.isEmpty(orderSnSuffix)){
            orderSnSuffix = "00001";
        }else {
            orderSnSuffix =String.format("%05d",Long.parseLong(orderSnSuffix) + 1L);
        }
        stringRedisTemplate.opsForValue().set(orderSnKey,orderSnSuffix,24 * 60 * 60 * 1000L, TimeUnit.MILLISECONDS);
        return orderSnKey+orderSnSuffix;
    }

    private void convertReceiveOrderDO(ReceiveOrderDO order,ReceiveOrderCreateVO param){
        DeliveryOrderDO deliveryOrderDO = deliveryOrderService.getDeliveryOrderDO(param.getDeliveryOrderId());
        if(deliveryOrderDO==null){
            throw new BusinessException(ResponseCode.ORDER_DELIVERY_ORDER_DOES_NOT_EXIST);
        }else if(!DeliveryOrderOuterStatusEnum.ALREADY_SUBMIT.getCode().equals(deliveryOrderDO.getOuterStatus())){
            throw new BusinessException(ResponseCode.ORDER_RECEIVE_ORDER_ADD_DELIVERY_STATUS_ERROR);
        }
        /*----------关联送货单参数--------------*/
        order.setDeliveryOrderId(deliveryOrderDO.getId());
        order.setDeliveryNo(deliveryOrderDO.getDeliveryNo());
        order.setDeliveryTime(deliveryOrderDO.getDeliveryTime());
        order.setSendTime(deliveryOrderDO.getSendTime());
        order.setVendorMemberId(deliveryOrderDO.getVendorMemberId());
        order.setVendorMemberName(deliveryOrderDO.getVendorMemberName());
        order.setVendorRoleId(deliveryOrderDO.getVendorRoleId());
        order.setReceiverBO(deliveryOrderDO.getReceiverBO());
        order.setDeliverBO(deliveryOrderDO.getDeliverBO());
        order.setLogisticsCompany(deliveryOrderDO.getLogisticsCompany());
        order.setLogisticsCompanyId(deliveryOrderDO.getLogisticsCompanyId());
        order.setLogisticsNo(deliveryOrderDO.getLogisticsNo());
        order.setCarNumbers(deliveryOrderDO.getExecutorBO().getCarNumbers());
        order.setDeliveryType(deliveryOrderDO.getDeliveryType());

        /*----------页面入参--------*/
        order.setDeliveryOrderId(param.getDeliveryOrderId());
        order.setRemark(param.getRemark());
        order.setDigest(param.getDigest());
        order.setReceiveTime(LocalDateTime.parse(param.getReceiveTime(),OrderServiceContants.DEFAULT_TIME_FORMATTER));
        //送货执行人
        LogisticsAddressBO executeVO = buildLogisticsAddressBO(param.getExecutorVO());
        if(executeVO!=null) {
            order.setExecutorBO(executeVO);
        }
        order.setOuterStatus(ReceiveOrderOuterStatusEnum.ALREADY_SUBMIT.getCode());
        //物流信息
        order.setUpdateTime(LocalDateTime.now());

    }

    private void convertReceiveOrderDOByUpdate(ReceiveOrderDO order,ReceiveOrderUpdateVO param){
        /*----------页面入参--------*/
        order.setRemark(param.getRemark());
        order.setDigest(param.getDigest());
        order.setReceiveTime(LocalDateTime.parse(param.getReceiveTime(),OrderServiceContants.DEFAULT_TIME_FORMATTER));
        //送货执行人
        LogisticsAddressBO executeVO = buildLogisticsAddressBO(param.getExecutorVO());
        if(executeVO!=null) {
            order.setExecutorBO(executeVO);
        }
        order.setUpdateTime(LocalDateTime.now());
    }

    private List<ReceiveOrderProductDO> convertReceiveOrderProductDOList(ReceiveOrderCreateVO param, ReceiveOrderDO order){
        Map<Long, BigDecimal> receiveMap = param.getProducts().stream().collect(Collectors.toMap(ReceiveOrderProductParamVO::getDeliveryOrderProductId, ReceiveOrderProductParamVO::getReceiveCount, (v1, v2) -> v1));
        List<DeliveryOrderProductDO> productList = deliveryOrderService.getProductList(param.getDeliveryOrderId(), param.getProducts().stream().map(ReceiveOrderProductParamVO::getDeliveryOrderProductId).collect(Collectors.toList()));
        if(productList!=null){
            return productList.stream().map(o ->{
                ReceiveOrderProductDO productDO=new ReceiveOrderProductDO();
                BigDecimal receiveCount = receiveMap.get(o.getId());
                if(receiveCount.compareTo(o.getDeliveryCount())<0){
                    throw new BusinessException(ResponseCode.ORDER_RECEIVE_ORDER_ADD_DELIVERY_RECEIVE_QUANTITY_ERROR);
                }
                BeanUtils.copyProperties(o,productDO);
                productDO.setId(null);
                productDO.setReceiveCount(receiveCount);
                productDO.setReceiveOrder(order);
                productDO.setDeliveryOrderProductId(o.getId());
                return productDO;

            }).collect(Collectors.toList());
        }
        return null;
    }

    @Transactional
    @Override
    public Wrapper<Void> createReceiveOrder(HttpHeaders headers, ReceiveOrderCreateVO param) {
        UserLoginCacheDTO loginUser = baseCacheService.needLoginFromBusinessPlatform(headers);
        //创建送货单
        ReceiveOrderDO order = new ReceiveOrderDO(loginUser.getMemberId(),loginUser.getMemberRoleId(),loginUser.getCompany());
        order.setReceiveNo(createOrderSn(BaseDeliveryEnum.RECEIVE_ORDER_SERIAL_NO.getName()));
        order.setCreateTime(LocalDateTime.now());
        convertReceiveOrderDO(order,param);
        receiveOrderRepository.save(order);

        //更新送货单状态为已收货
        deliveryOrderService.updateStatus(loginUser,param.getDeliveryOrderId(),DeliveryOrderOuterStatusEnum.RECEIVED.getCode());

        //物料信息
        List<ReceiveOrderProductDO> productDOS = convertReceiveOrderProductDOList(param, order);
        if(productDOS==null){
            throw new BusinessException(ResponseCode.ORDER_DELIVERY_ORDER_PRODUCT_DOES_NOT_EXIST);
        }
        receiveOrderProductRepository.saveAll(productDOS);

        //更新订单收送数量
        List<ProductReceiveOrDeliveryVO> deliveryQuantityList = productDOS.stream().map(o -> {
            ProductReceiveOrDeliveryVO vo = new ProductReceiveOrDeliveryVO();
            vo.setQuantity(o.getReceiveCount());
            vo.setOrderProductId(o.getOrderProductId());
            return vo;
        }).collect(Collectors.toList());
        Wrapper<Void> orderWrapper = baseOrderDeliveryService.checkCreateBuyerReceive(loginUser, order, deliveryQuantityList);
        if(orderWrapper.getCode()!=ResponseCode.SUCCESS.getCode()){
            log.warn("收货单:更新订单数量失败,input:{},result:{}", JSONUtil.toJsonStr(deliveryQuantityList),JSONUtil.toJsonStr(orderWrapper));
            throw new BusinessException(orderWrapper.getCode(),orderWrapper.getMessage());
        }

        //更新送货计划数量
        deliveryPlanService.updateDeliveryPlanOrder(productDOS.stream().map(ReceiveOrderProductDO::getOrderProductId).collect(Collectors.toList()));

        //流转记录
        historyService.saveVendorOuterHistoryByReceiveOrder(loginUser.getMemberId(),loginUser.getMemberRoleId(),loginUser.getUserName(), loginUser.getUserOrgName(),loginUser.getMemberRoleName(),order.getId(),order.getReceiveNo(), DeliveryOperationEnum.CREATE_RECEIVE_ORDER, ReceiveOrderOuterStatusEnum.ALREADY_SUBMIT,param.getRemark(), DeliveryHistoryTypeEnum.RECEIVE_ORDER.getCode());
        return Wrapper.success();
    }


    @Override
    public Wrapper<ReceiveOrderDetailVO> detail(HttpHeaders headers, IdVO request) {
        UserLoginCacheDTO loginUser = baseCacheService.needLoginFromBusinessPlatform(headers);
        ReceiveOrderDO receiverOrderDO = receiveOrderRepository.findById(request.getId()).orElse(null);
        if(receiverOrderDO==null){
            return Wrapper.fail(ResponseCode.ORDER_RECEIVE_ORDER_DOES_NOT_EXIST);
        }
        //数据权限校验
        if(!isMemberData(loginUser,receiverOrderDO)){
            return Wrapper.fail(ResponseCode.DATA_AUTH_NOT_ALLOWED);
        }
        ReceiveOrderDetailVO response=new ReceiveOrderDetailVO();
        BeanUtils.copyProperties(receiverOrderDO,response);
        response.setDeliverVO(convertLogisticsAddressVO(receiverOrderDO.getDeliverBO()));
        response.setReceiverBO(convertLogisticsAddressVO(receiverOrderDO.getReceiverBO()));
        response.setExecutorVO(convertLogisticsAddressVO(receiverOrderDO.getExecutorBO()));
        response.setReceiveTime(DateTimeUtil.formatDate(receiverOrderDO.getReceiveTime()));
        response.setSendTime(DateTimeUtil.formatMinuteTime(receiverOrderDO.getSendTime()));
        response.setCarNumbers(receiverOrderDO.getCarNumbers());
        response.setOuterStatusName(ReceiveOrderOuterStatusEnum.getNameByCode(receiverOrderDO.getOuterStatus()));
        //外部流转记录
        response.setOuterHistoryList(historyService.listDeliveryOuterHistory(receiverOrderDO.getId(), DeliveryHistoryTypeEnum.RECEIVE_ORDER.getCode()));
        return Wrapper.success(response);
    }

    @Transactional
    @Override
    public Wrapper<Void> update(HttpHeaders headers, ReceiveOrderUpdateVO request) {
        UserLoginCacheDTO loginUser = baseCacheService.needLoginFromBusinessPlatform(headers);
        ReceiveOrderDO order = receiveOrderRepository.findById(request.getId()).orElse(null);
        if(order==null){
            return Wrapper.fail(ResponseCode.ORDER_RECEIVE_ORDER_DOES_NOT_EXIST);
        }else if(!isCreator(loginUser,order)){
            return Wrapper.fail(ResponseCode.DATA_AUTH_NOT_ALLOWED);
        }else if(!ReceiveOrderOuterStatusEnum.ALREADY_SUBMIT.getCode().equals(order.getOuterStatus())){
            return Wrapper.fail(ResponseCode.ORDER_RECEIVE_ORDER_UPDATE_STATUS_ERROR);
        }
        //收货单覆盖
        convertReceiveOrderDOByUpdate(order,request);
        receiveOrderRepository.saveAndFlush(order);

        /*修改不能更新明细数据
        //删除历史物料
        receiveOrderProductRepository.deleteByReceiveOrder(order);
        //物料信息
        List<ReceiveOrderProductDO> productDOS = convertReceiveOrderProductDOList(request, order);
        if(productDOS==null){
            throw new BusinessException(ResponseCode.ORDER_DELIVERY_ORDER_PRODUCT_DOES_NOT_EXIST);
        }
        receiveOrderProductRepository.saveAll(productDOS);
        */

        //无需更新订单发送数量，因为不更新明细

        //流转记录
        historyService.saveVendorOuterHistoryByReceiveOrder(loginUser.getMemberId(),loginUser.getMemberRoleId(),loginUser.getUserName(), loginUser.getUserOrgName(),loginUser.getMemberRoleName(),order.getId(),order.getReceiveNo(),DeliveryOperationEnum.MODIFY_RECEIVE_ORDER, ReceiveOrderOuterStatusEnum.ALREADY_SUBMIT,request.getRemark(), DeliveryHistoryTypeEnum.RECEIVE_ORDER.getCode());
        return Wrapper.success();
    }

    @Transactional
    @Override
    public Wrapper<Void> invalid(HttpHeaders headers, InvalidVO request) {
        UserLoginCacheDTO loginUser = baseCacheService.needLoginFromBusinessPlatform(headers);
        ReceiveOrderDO order = receiveOrderRepository.findById(request.getId()).orElse(null);
        if(order==null){
            return Wrapper.fail(ResponseCode.ORDER_RECEIVE_ORDER_DOES_NOT_EXIST);
        }else if(!isCreator(loginUser,order)){
            return Wrapper.fail(ResponseCode.DATA_AUTH_NOT_ALLOWED);
        }else if(!ReceiveOrderOuterStatusEnum.ALREADY_SUBMIT.getCode().equals(order.getOuterStatus())){
            return Wrapper.fail(ResponseCode.ORDER_RECEIVE_ORDER_INVALID_STATUS_ERROR);
        }
        order.setOuterStatus(ReceiveOrderOuterStatusEnum.INVALID.getCode());
        order.setUpdateTime(LocalDateTime.now());
        receiveOrderRepository.saveAndFlush(order);

        //TODO 更新订单发送数量

        //更新送货单状态为已提交
        deliveryOrderService.updateStatus(loginUser,order.getDeliveryOrderId(),DeliveryOrderOuterStatusEnum.ALREADY_SUBMIT.getCode());

        //流转记录
        historyService.saveVendorOuterHistoryByReceiveOrder(loginUser.getMemberId(),loginUser.getMemberRoleId(),loginUser.getUserName(), loginUser.getUserOrgName(),loginUser.getMemberRoleName(),order.getId(),order.getReceiveNo(),DeliveryOperationEnum.INVALID_NOTICE_ORDER, ReceiveOrderOuterStatusEnum.INVALID,request.getRemark(), DeliveryHistoryTypeEnum.RECEIVE_ORDER.getCode());
        return Wrapper.success();
    }

    @Override
    public Wrapper<PageData<ReceiveOrderQueryVO>> pageByVendor(HttpHeaders headers, ReceiveOrderPageVO pageVO) {
        UserLoginCacheDTO loginUser = baseCacheService.needLoginFromBusinessPlatform(headers);
        return Wrapper.success(pageBase(new MemberAndRoleIdDTO(loginUser.getMemberId(),loginUser.getMemberRoleId()),null,pageVO));
    }
}
